#include "stdafx.h"
#include "MediaTypeConvert.h"
#include <initguid.h>

extern "C" {
#include <libavformat/avformat.h>
}


DEFINE_MEDIATYPE_GUID(MFVideoFormat_RV40, FCC('RV40'));
DEFINE_MEDIATYPE_GUID(MFAudioFormat_COOK, FCC('COOK'));

MediaTypeMap const MediaTypeConvert::table_[] = {
		{ AV_CODEC_ID_RV40, MFVideoFormat_RV40, 1 },
		{ AV_CODEC_ID_H264, MFVideoFormat_H264, 0 },
		{ AV_CODEC_ID_HEVC, MFVideoFormat_HEVC, 1 },
		{ AV_CODEC_ID_MPEG4, MFVideoFormat_MP4V, 0 },
		{ AV_CODEC_ID_VC1, MFVideoFormat_WMV3, 0 },

		{ AV_CODEC_ID_AAC, MFAudioFormat_AAC, 0 },
		{ AV_CODEC_ID_MP3, MFAudioFormat_MP3, 0 },
		{ AV_CODEC_ID_WMAV2, MFAudioFormat_WMAudioV8, 0 },
		{ AV_CODEC_ID_AC3, MFAudioFormat_Dolby_AC3, 0 },
		{ AV_CODEC_ID_EAC3, MFAudioFormat_Dolby_DDPlus, 0 },
		{ AV_CODEC_ID_COOK, MFAudioFormat_COOK, 2 },

};

MediaTypeMap const * MediaTypeConvert::find_by_ffmpeg_type(
	int ffmpeg_type)
{
	MediaTypeMap const * codec = NULL;
	for (int i = 0; i < count(); i++)
	{
		if (table_[i].ffmpeg_mediaType == ffmpeg_type)
			codec = &table_[i];
	}
	return codec;
}


MediaTypeMap const * MediaTypeConvert::find_by_mf_type(
	GUID mf_type)
{
	MediaTypeMap const * codec = NULL;
	for (int i = 0; i < count(); i++)
	{
		if (table_[i].mf_mediaType == mf_type)
			codec = &table_[i];
	}
	return codec;
}


size_t MediaTypeConvert::count()
{
	return sizeof(table_) / sizeof(table_[0]);
}

MediaTypeMap const * MediaTypeConvert::table()
{
	return table_;
}